package cn.mxz.service.impl;

import cn.mxz.mapper.ProductMapper;
import cn.mxz.mapper.ProductParamsMapper;
import cn.mxz.pojo.Product;
import cn.mxz.pojo.ProductParams;
import cn.mxz.pojo.ProductSku;
import cn.mxz.pojo.ResultData;
import cn.mxz.service.ProductService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProductServiceImpl implements ProductService {
    @Autowired
    private ProductParamsMapper productParamsMapper;
    @Autowired
    private ProductMapper productMapper;

    @Override
    public ProductParams getProductParamsById(String pid) {
        QueryWrapper<ProductParams> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("product_id", pid);
        ProductParams productParams = productParamsMapper.selectOne(queryWrapper);
        return productParams;
    }
    @Override
    public ResultData getProductbycategoryid(Integer cid) {
        List<Product> selectproductbycid = productMapper.selectproductbycid(cid);

        if(selectproductbycid==null){
            return  new ResultData(107,"抱歉没有此类型的商品");
        }else {
            return  new ResultData(0,"查询成功",selectproductbycid);
        }
    }

    @Override
    public ResultData getprdlike(String msg) {
        String msg1="%"+msg+"%";
        List<Product> sellectlike = productMapper.sellectlike(msg1);
        if (sellectlike == null) {
            return new ResultData(155, "无该商品");
        }
        return new ResultData(0, "ok", sellectlike);
    }

    @Override
    public ResultData selectSkuById(String productId) {
        List<ProductSku> productSkuList = productMapper.selectByProductId(productId);
        if (productSkuList.size() == 0) return new ResultData(108,"该商品暂无信息");
        return new ResultData(0,"查询成功");
    }

    @Override
    public List<Product> findProductByName(String text) {
        String findText = "%"+text+"%";
        List<Product> productByName = productMapper.findProductByName(findText);
        return productByName;
    }
}
